package com.turtle3d.util;

import java.util.Random;

import javax.vecmath.Matrix4f;

/**
 * Singleton helper for random numbers generation.
 * 
 * @author Marek Paterczyk <marek.paterczyk@gmail.com>
 * 
 */
public class Randomizer
{
	private static Randomizer randomizer = null;
	
	private Random random = new Random();		

	public static Randomizer getRandomizer()
	{
		if (randomizer == null) 
			randomizer = new Randomizer();
		return randomizer;
	}

	public Random getRandom()
	{
		return random;
	}
	
	public Matrix4f nextConeAngleTransformation(float angle, boolean gaussian){
		Matrix4f temp = new Matrix4f();	
		temp.setIdentity();
		temp.rotY((float)(random.nextFloat()*2*Math.PI));
		
		Matrix4f temp2 = new Matrix4f();	
		temp2.setIdentity();
		
		float randAngle;
		if(!gaussian)
			randAngle = (float)(-Math.PI)*(random.nextFloat()*angle*0.5f-angle)/180f;
		else
			randAngle = (float)(-Math.PI)*((float)random.nextGaussian()*angle*0.5f)/180f;
			
			
		temp2.rotZ(randAngle);
		
		temp.mul(temp2);				
		
		return temp;
				
	}
	
	public float nextVariation(){
		return 2f*(random.nextFloat()-0.5f);
	}
	
	

}
